﻿using TouchSocket.Core;
using TouchSocket.Sockets;

namespace Om.Core.Singleton;

public class CameraUdpManager :SingletonBase<CameraUdpManager>
{
    private Dictionary<string, string> _clientAddrDict = new() { };
    private UdpSession _udpSession = new UdpSession();
    public void Start()
    {
        _udpSession.Setup(new TouchSocketConfig()
            .SetUdpDataHandlingAdapter(()=> new UdpPackageAdapter())); //只发送数据，不接收，不设端口
        _udpSession.Start();
        
    }

    public void Send(string cameraDesc, byte[] data)
    {
        var addr = $"{DevicesConfig.Instance.CameraUdpIp}:{DevicesConfig.Instance.CameraUdpPorts[cameraDesc]}";
        _udpSession.Send(new IPHost(addr).EndPoint, data);
    }
}